package org.yelongframework.yaml.resolver;

import java.io.InputStream;
import java.util.Objects;

import org.yaml.snakeyaml.Yaml;
import org.yelongframework.yaml.YamlMap;
import org.yelongframework.yaml.factory.YamlMapFactory;

/**
 * yaml解析器默认实现
 * 
 * @since 1.0.0
 */
public class DefaultYamlResolver implements YamlResolver {

	private final YamlMapFactory yamlMapFactory;

	private final Yaml yaml;

	public DefaultYamlResolver(YamlMapFactory yamlMapFactory, Yaml yaml) {
		this.yamlMapFactory = Objects.requireNonNull(yamlMapFactory);
		this.yaml = Objects.requireNonNull(yaml);
	}

	@Override
	public YamlMap resolve(InputStream inputStream) {
		return yamlMapFactory.create(yaml.load(inputStream));
	}

	@Override
	public YamlMapFactory getYamlMapFactory() {
		return yamlMapFactory;
	}

}
